<template>
  <div>
    <h1>新建英雄</h1>
    <el-form label-width="80px">
      <el-tabs type="border-card">
        <el-tab-pane label="基础信息">
          <el-form-item label="名称">
            <el-input v-model="formInfo.name"></el-input>
          </el-form-item>

          <el-form-item label="称号">
            <el-input v-model="formInfo.title"></el-input>
          </el-form-item>

          <el-form-item label="图标">
            <el-upload
              class="avatar-uploader"
              :action="imgUploadUrl"
              :show-file-list="false"
              :on-success="handleImgSuccess"
            >
              <img v-if="formInfo.icon" :src="formInfo.icon" class="avatar" />
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>

          <el-form-item label="类型">
            <el-select v-model="formInfo.categories" multiple>
              <el-option
                v-for="item of categoryList"
                :key="item._id"
                :label="item.name"
                :value="item._id"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="难度">
            <el-rate
              class="show-rate"
              v-model="formInfo.scores.difficult"
              :max="10"
              show-score
            ></el-rate>
          </el-form-item>

          <el-form-item label="技能">
            <el-rate
              class="show-rate"
              v-model="formInfo.scores.skills"
              :max="10"
              show-score
            ></el-rate>
          </el-form-item>

          <el-form-item label="攻击">
            <el-rate
              class="show-rate"
              v-model="formInfo.scores.attack"
              :max="10"
              show-score
            ></el-rate>
          </el-form-item>

          <el-form-item label="生存">
            <el-rate
              class="show-rate"
              v-model="formInfo.scores.survive"
              :max="10"
              show-score
            ></el-rate>
          </el-form-item>

          <el-form-item label="顺风出装">
            <el-select v-model="formInfo.advantageEquips" multiple>
              <el-option
                v-for="item of equipList"
                :key="item._id"
                :label="item.name"
                :value="item._id"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="逆风出装">
            <el-select v-model="formInfo.disadvantageEquips" multiple>
              <el-option
                v-for="item of equipList"
                :key="item._id"
                :label="item.name"
                :value="item._id"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="使用技巧">
            <el-input type="textarea" v-model="formInfo.usageTips"></el-input>
          </el-form-item>

          <el-form-item label="对抗技巧">
            <el-input type="textarea" v-model="formInfo.battleTips"></el-input>
          </el-form-item>

          <el-form-item label="团战思路">
            <el-input type="textarea" v-model="formInfo.teamTips"></el-input>
          </el-form-item>
        </el-tab-pane>
        <el-tab-pane label="技能">配置管理</el-tab-pane>
        <el-tab-pane label="英雄关系">角色管理</el-tab-pane>
      </el-tabs>
      <el-form-item class="btn">
        <el-button type="primary" @click="save">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { HERO, CATEGORY, EQUIP } from '@/utils/const'
import { commonMixin } from '@/utils/mixin'

export default {
  mixins: [commonMixin],
  data () {
    return {
      equipList: [],
      categoryList: []
    }
  },
  created () {
    this.getCategoryList()
    this.getEquipList()
  },
  methods: {
    save () {
      this.add(HERO)
    },
    async getCategoryList () {
      const res = await this.$api.getList(CATEGORY)
      if (res.meta.status === 0) {
        this.categoryList = res.data
      }
      // console.log(res)
    },
    async getEquipList () {
      const res = await this.$api.getList(EQUIP)
      if (res.meta.status === 0) {
        this.equipList = res.data
      }
      // console.log(res)
    }
  },
}
</script>

<style scoped>
.show-rate {
  margin-top: 0.6rem;
}

.btn {
  margin-top: 1rem;
}
</style>